<?php
@set_time_limit(120);
error_reporting(E_ALL);

$PHP_SELF = $_SERVER['PHP_SELF'];

if (isset($_POST['player'])){
	$player = $_POST['player'];
	$autostart = isset($_POST['autostart']);
	$loop = isset($_POST['loop']);
	$visible = isset($_POST['visible']);
}else{
	$player = 'default';
	$autostart = true;
	$loop = false;
	$visible = true;
}

if(isset($_GET['onkai'])){
    $save_dir = 'tmp/';
	srand((double)microtime()*1000000);
	$file = $save_dir.rand().'.mid';

	/****************************************************************************
	MIDI CLASS CODE
	****************************************************************************/
	require_once('./classes/midi.class.php');

	$n = $_GET['onkai'];


	$txt = "MFile 1 2 480
MTrk
0 TimeSig 4/4 24 8
0 Tempo 400000
0 Meta TrkEnd
TrkEnd
MTrk
0 PrCh ch=5 p=0
0 On ch=5 n=$n v=127
120 Off ch=5 n=$n v=127
720 Meta TrkEnd
TrkEnd";


	$midi = new Midi();
	$midi->importTxt($txt);
	$midi->saveMidFile($file, 0666);
	$midi->playMidFile($file,$visible,$autostart,$loop,$player);
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Midiほにゃらら</title>
<link rel="stylesheet" type="text/css" href="css/gakuhu.css" />
</head>
<body>
<div id="contentLeft">
プレイヤーを選んでください:
<?
$players = array(
	'default'=>'Default',
	'quicktime'=>'Quicktime',
	'crescendo'=>'Crescendo',
	'bgsound'=>'IE Win BgSound',
	'windowsmedia'=>'Windows Media',
	'beatnik'=>'Beatnik',
	'ogg_html5'=>'OGG HTML5 Player'
);
foreach ($players as$k=>$v){
	echo '<input type="radio" name="player" value="'.$k.'"'.($player==$k?' checked="checked"':'').' />'.$v."\n";
}
?>
</div>
<br />
<div id="contentLeft">

<table  cellspacing="0" cellpadding="0" >
  <tr>
      <td class="top0">
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
<font color="#ffffff">bbbbbbbbbbbbbbb</font>
      </td>
      <td class="top1">
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
<font color="#ffffff">bbbbbbbbbbbbbbb</font>
            <br />
      </td>
      <td class="score2">
<font color="#ffffff">bbbbbbbbbbbbbbb</font>
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <b>1</b>
            <br />
<img src="images/4bu_ompu.png"  width="34px" height="142px" />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
            <br />
      </td>
      <td class="score1">
      <a href="f5">-</a>
            <br />
      <a href="e5"><font color="red">-</font></a>
            <br />
      <a href="d5">-</a>
            <br />
      <a href="c5"><font color="red">-</font></a>
            <br />
      <a href="b5">-</a>
            <br />
      <a href="a5"><font color="red">-</font></a>
            <br />
      <a href="g4">-</a>
            <br />
      <a href="f4">-</a>
            <br />
      <a href="e4">-</a>
            <br />
      <a href="d4">-</a>
            <br />
      <a href="c4">-</a>
            <br />
      <a href="b4">-</a>
            <br />
      <a href="a4">-</a>
            <br />
      <a href="g3">-</a>
            <br />
      <a href="score.php?onkai=41">-</a>
            <br />
      <a href="e3">-</a>
            <br />
      <a href="d3">-</a>
            <br />
      <a href="c3"><font color="red">-</font></a>
            <br />
      <a href="b3">-</a>
            <br />
      <a href="a3"><font color="red">-</font></a>
            <br />
      <a href="g2">-</a>
            <br />
      <a href="f2"><font color="red">-</font></a><font color="#ffffff">bbbbbbbbbbbbbb</font>
            <br />
      <a href="e2">-</a>
      </td>
      <td class="score1">
      <a href="f5">-</a>
            <br />
      <a href="e5"><font color="red">-</font></a>
            <br />
      <a href="d5">-</a>
            <br />
      <a href="c5"><font color="red">-</font></a>
            <br />
      <a href="b5">-</a>
            <br />
      <a href="a5"><font color="red">-</font></a>
            <br />
      <a href="g4">-</a>
            <br />
      <a href="f4">-</a>
            <br />
      <a href="e4">-</a>
            <br />
      <a href="d4">-</a>
            <br />
      <a href="c4">-</a>
            <br />
      <a href="b4">-</a>
            <br />
      <a href="a4">-</a>
            <br />
       <a href="score.php?onkai=43">-</a>
            <br />
      <a href="score.php?onkai=41">-</a>
            <br />
      <a href="e3">-</a>
            <br />
      <a href="d3">-</a>
            <br />
      <a href="c3"><font color="red">-</font></a>
            <br />
      <a href="b3">-</a>
            <br />
      <a href="a3"><font color="red">-</font></a>
            <br />
      <a href="g2">-</a>
            <br />
      <a href="f2"><font color="red">-</font></a><font color="#ffffff">bbbbbbbbbbbbbb</font>
            <br />
      <a href="e2">-</a>
      </td>
      <td class="score1">
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <font color="#ffffff">bbbbbbbbbbbbbbb</font>
      </td>
      <td class="scoreE0" >
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
      <font color="#ffffff">bbbbbbbbbbbbbbb</font>
      </td>

  </tr>
</table>
</div>
<?php
//$onkai = array();
//$onkai = $_GET["onkai2"];
//$onkai = $_GET["onkai3"];
//echo $onkai."<br />";
//print_r($onkai);
?>


<br />
<br />
<input type="submit" name="play" value=" PLAY! " />


	<br /><br />
	<input type="button" name="download" value="Save as SMF (*.mid)" onclick="self.location.href='download.php?f=<?=urlencode($file)?>'" />


</body>
</html>
